<template>
	<view class="mainBg h100">
		<navbar title="订单详情" />
		<view class="content info" v-if="orderInfo.scene == `course` && courseInfo">
			<view class="left">
				<image :src="courseInfo.courseImageUrl" mode="aspectFill"></image>
				<view class="text">
					{{courseInfo.courseName}}
				</view>
			</view>
			<view class="price">
				￥{{orderInfo.paymentTotal}}
			</view>
		</view>
		<view class="content info"  v-if="orderInfo.scene == `recharge`">
			<view class="left">
				<view class="text">
					{{orderInfo.orderDesc}}
				</view>
			</view>
			<view class="price">
				￥{{orderInfo.paymentTotal}}
			</view>
		</view>
		
		<view class="content">
			<view class="col">
				<text>总计</text>
				<text>￥{{orderInfo.total}}</text>
			</view>
			<view class="col">
				<text>优惠</text>
				<text v-if="orderInfo.discountTotal > 0" class="price">-￥{{orderInfo.discountTotal}}</text>
				<text v-else>无</text>
			</view>
			<view class="col">
				<text>实际付</text>
				<text class="price">￥{{orderInfo.paymentTotal}}</text>
			</view>
		</view>
		<view class="content">
			<view class="col">
				<text>订单编号</text>
				<view @click="copy(orderInfo.orderSn)">
					<text>{{orderInfo.orderSn}}</text>
					<text class="copy">复制</text>
				</view>
			</view>
			<view class="col">
				<text>订单状态</text>
				<view class="status pending" v-if="orderInfo.orderStatus == 0">
					待支付
				</view>
				<view class="status success" v-if="orderInfo.orderStatus == 1">
					已完成
				</view>
				<view class="status refund2" v-if="orderInfo.orderStatus == 3">
					已退款
				</view>
				<view class="status expired" v-if="orderInfo.orderStatus == 4 || orderInfo.orderStatus == 5">
					已关闭
				</view>
			</view>
			<view class="col">
				<text>下单时间</text>
				<text>{{orderInfo.returnTime}}</text>
			</view>
			<view class="col">
				<text>付款时间</text>
				<text>{{orderInfo.returnTime}}</text>
			</view>
			<view class="col">
				<text>支付方式</text>
				<text v-if="orderInfo.payType === `walletpay`">钱包支付</text>
				<text v-if="orderInfo.payType === `wxpay`">微信支付</text>
				<text v-if="orderInfo.payType === `alipay`">支付宝支付</text>
			</view>
		</view>
		<view class="refund" @click="handleOpen" v-if="orderInfo.orderStatus === `1`">
			确定退款
		</view>
		<view class="payment" v-if="orderInfo.orderStatus === `0`">
			<view class="price">
				￥{{orderInfo.paymentTotal}}
			</view>
			<view class="btn">
				立即支付
			</view>
		</view>
		<view class="seat"></view>
		<refund ref="refundRef":orderId="orderId"/>
	</view>
</template>

<script>
	import refund from "./components/refund.vue"
	export default {
		components: {
			refund
		},
		data() {
			return {
				orderId:'',
				orderInfo:{},
				courseInfo:{},
			}
		},
		onLoad(option) {
			this.orderId = option.orderId
			this.getInfo()
		},
		methods: {
			getInfo() {
				this.$post("/order/info",{orderId:this.orderId}).then(res => {
					this.orderInfo = res.data
					this.courseInfo = this.orderInfo.goodsList[0]
				})
			},
			copy(code) {
				uni.setClipboardData({
					data: code,
					success: function() {
						this.$toast("复制成功")
					}
				});
			},
			handleOpen() {
				this.$refs.refundRef.open()
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #35CBAD;
	}

	.content {
		background-color: #fff;
		margin-bottom: 20rpx;
		padding: 20rpx 40rpx;
		font-size: 28rpx;

		.col {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx 0;

			.price {
				color: #EB3323;
			}

			.copy {
				color: #999;
				margin-left: 16rpx;
			}
		
				.pending {
					color: $uni-color-warning;
					font-weight: bold;
				}
				.success {
					color: $uni-color-success;
					font-weight: bold;
				}
				.refund2 {
					color: $uni-color-primary;
					font-weight: bold;
				}
				.expired {
					color: $uni-color-error;
					font-weight: bold;
				}
			
		}
	}

	.info {
		display: flex;
		justify-content: space-between;
		padding: 40rpx;

		.left {
			display: flex;
			width: calc(100% - 160rpx);

			image {
				width: 140rpx;
				height: 100rpx;
				border-radius: 8rpx;
				overflow: hidden;
			}

			.text {
				font-weight: bold;
				font-size: 32rpx;
				padding-left: 10rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				text {
					display: block;
					font-size: 24rpx;
					color: #999;
					font-weight: normal;
				}
			}
		}

		.price {
			padding: 10rpx 0;
			font-size: 32rpx;
		}
	}

	.refund {
		margin: 80rpx auto;
		width: 250rpx;
		line-height: 90rpx;
		border-radius: 25px;
		background-color: $assist-color2;
		// color: #fff;
		border: 2rpx solid #A4ADB3;
		font-size: 36rpx;
		text-align: center;
	}

	.seat {
		height: 110rpx;
	}

	.payment {
		background-color: #fff;
		height: 110rpx;
		width: 100%;
		position: fixed;
		left: 0%;
		bottom: 0;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 40rpx;

		.price {
			color: #EB3323;
			font-weight: bold;
			font-size: 40rpx;
		}

		.btn {
			width: 160rpx;
			line-height: 60rpx;
			border-radius: 8rpx;
			background-color: $assist-color2;
			color: #fff;
			font-size: 24rpx;
			font-weight: bold;
			text-align: center;
		}
	}
</style>